/*
 * 文件名：AutoOpenServiceImpl.java	 
 * 时     间：上午11:00:25
 * 作     者：lyf      
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.local.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cz073586.tools.util.Tools;
import com.cz073586.tools.util.UUIDGenerateUtil;
import com.local.dao.mapers.AutoOpenMapper;
import com.local.model.AutoOpen;
import com.local.model.AutoOpenExample;
import com.local.service.face.AutoOpenService;
import com.qianhai.common.dao.face.BaseMapper;
import com.qianhai.common.entity.PageInfo;
import com.qianhai.common.exception.BaseException;
import com.qianhai.common.service.impl.BaseServiceImpl;

/**
 * 类描述:这里是类描述
 * 
 * @ClassName: AutoOpenServiceImpl
 * @author Administrator
 * @date 2015年11月24日 上午11:00:25
 */
@Service
public class AutoOpenServiceImpl extends
		BaseServiceImpl<AutoOpenExample, AutoOpen, String> implements
		AutoOpenService
{
	
	@Autowired
	private AutoOpenMapper autoOpenMapper;
	
	@Override
	public boolean getCurrentSwitch()
	{
		List<AutoOpen> list = autoOpenMapper
				.queryByPage(new PageInfo<AutoOpen>());
		if (!Tools.isEmpty(list) && !list.isEmpty()
				&& list.get(0).getType() == 2)
		{
			return true;
		}
		return false;
	}
	
	@Override
	public Integer modifySwitch(int isOpen)
	{
		try
		{
			List<AutoOpen> list = autoOpenMapper
					.queryByPage(new PageInfo<AutoOpen>());
			if (!Tools.isEmpty(list) && !list.isEmpty())
			{
				list.get(0).setType(isOpen);
				return autoOpenMapper.updateByPrimaryKey(list.get(0));
			}
			
			AutoOpen info = new AutoOpen();
			info.setUuid(UUIDGenerateUtil.generate());
			info.setType(isOpen);
			return autoOpenMapper.insertSelective(info);
			
			
		} catch (Throwable e)
		{
			log.error(e.getMessage(), e);
			throw new BaseException(e.getMessage());
		}
	}
	
	@Override
	public BaseMapper<AutoOpenExample, AutoOpen, String> getMapper()
	{
		
		return autoOpenMapper;
	}
	
}
